<template>
	<account-page :title="title" :desc="desc">
		<view class="content">
			<view class="login-bg">
				<view class="login-card">
					<view class="login-head">登 录</view>
					<view class="login-input login-margin-b">
						<input type="text" v-model="model.user" placeholder="请输入账户名" />
					</view>
					<view class="login-input">
						<input type="password" v-model="model.password" placeholder="请输入密码" />
					</view>
					<view class="login-function">
						<!-- <view class="login-forget" @click="openPage('forget/forget')">忘记密码</view>
						<view class="login-register" @click="openPage('forget/forget')">快速注册></view> -->
					</view>
				</view>
			</view>
			<view class="login-btn">
				<button class="landing" type="primary" @click="submit">登 录</button>
			</view>
		</view>
		<u-modal v-model="paramShow" title="隐私政策" width="85%" class="param-model" :show-cancel-button="true" confirmText="同意" cancelText="暂不使用"
			@confirm="confirmModelParams">
			<view class="slot-content">
				<view style="padding: 15px;line-height: 22px;">
					请您务必仔细阅读并透彻理解"隐私政策"各条款,你可以阅读<text style="color: cornflowerblue;" @click="goTo">《隐私政策》</text>了解详细信息，如果你同意，请点击"同意"接受我们的服务
				</view>
			</view>
			</u-modal>
		<view style="font-size: 12px;color: cornflowerblue;margin-top: calc(100vh - 980upx);text-align: center;"><text @click="goTo(1)">服务协议</text> <text style="padding: 0 20upx;">|</text> <text @click="goTo(2)">隐私政策</text></view>
	</account-page>
</template>

<script>
	import {
		userlogin,
		getPublicKey
	} from '../../../api/eqment/index.js'
	import jsencrypt from '@/js_sdk/jsencrypt-Rsa/jsencrypt/jsencrypt.vue'
	export default {
		data() {
			return {
				title: '',
				desc: '',
				paramShow:false,
				form: {
					errorType: ['message'],
					labelPosition: 'top'
				},
				model: {
					/* 账号 */
					user: '',
					/* 密码 */
					password: ''
				},
				rules: {
					user: [{
							required: true,
							message: '请输入账户名',
							trigger: ['change', 'blur']
						},
						// {
						// 	validator: (rule, value, callback) => {
						// 		return this.$u.test.mobile(value);
						// 	},
						// 	message: '手机号格式不正确',
						// 	trigger: ['change', 'blur']
						// }
					],
					password: [{
							required: true,
							message: '请输入密码',
							trigger: ['change', 'blur']
						},
						// {
						// 	min: 6,
						// 	max: 20,
						// 	message: '密码长度在6到20个字符',
						// 	trigger: ['change', 'blur']
						// },
						// {
						// 	pattern: /^[0-9a-zA-Z]*$/g,
						// 	transform(value) {
						// 		return String(value);
						// 	},
						// 	message: '密码为字母或数字',
						// 	trigger: ['change', 'blur']
						// }
					]
				}
			};
		},
		created() {
			// if(uni.getStorageSync('storage_secrets') && uni.getStorageSync('storage_secrets') == 1){
			// 	this.paramShow = false
			// }else{
			// 	this.paramShow = true
			// }
		},
		methods: {
			openPage(path) {
				this.$u.route({
					url: '/pages/account/' + path
				});
			},
			submit() {
				// if(uni.getStorageSync('storage_secrets') && uni.getStorageSync('storage_secrets') == 1){
				// 	this.paramShow = false
				// }else{
				// 	this.paramShow = true
				// 	return false
				// }
				uni.showLoading({
					title: '登录中......',
					mask: true
				});
				
				getPublicKey({}).then((res) => {
					var aesuncrypt_Acount = jsencrypt.setEncrypt(res,this.model.user)
					var aesuncrypt_pwd = jsencrypt.setEncrypt(res,this.model.password)
					userlogin({
						account: aesuncrypt_Acount,
						pwd: aesuncrypt_pwd,
					}).then((res) => {
						uni.hideLoading();
						if(res.success){
							uni.setStorageSync('Authorization', res.expandData)
							// sessionStorage.setItem('Authorization', res.expandData)
							uni.setStorageSync('uer_role_value',res.roleValue)

							this.$u.vuex('vuex_user.hasLogin', true);
							this.$u.vuex('vuex_user.userId', this.model.user);
							this.$u.vuex('vuex_user.userName', this.model.user);
							this.$u.vuex('vuex_token', res.expandData);
							uni.switchTab({
								url: '/pages/index/index1'
							});
						}else{
							this.$u.toast(res.message);
						}
						
					})
				})
				// uni.request({
				// 	url: this.$website.url2 + 'account/eam',
				// 	data: {
				// 		loginname: this.model.user,
				// 		password: this.model.password,
				// 		type: 'APP'
				// 	},
				// 	success: res => {
				// 		uni.hideLoading();
				// 		if (res.data.code == 200) {
				// 			console.log('///////',res)
				// 			this.$u.vuex('vuex_user.hasLogin', true);
				// 			this.$u.vuex('vuex_user.userId', this.model.user);
				// 			this.$u.vuex('vuex_user.userName', res.data.remark);
				// 			this.$u.vuex('vuex_token', res.data.data);
				// 			uni.switchTab({
				// 				url: '/pages/index/index1'
				// 			});
				// 		} else {
				// 			this.$u.toast(res.data.msg);
				// 		}
				// 	}
				// });
			},
			goTo(val){
				if(val == 1){
					this.$u.route({
						url: '/pages/xieyi/index'
					});
				}else{
					this.$u.route({
						url: '/pages/secrets/secrets'
					});
				}
				
			},
			confirmModelParams(){
				uni.setStorageSync('storage_secrets', '1');
			}
		},
		onReady() {
			// this.$refs.uForm.setRules(this.rules);
		}
	};
</script>

<style lang="scss" scoped>
	.account-form-box {
		padding: 0 32rpx;
	}

	.landing {
		height: 84upx;
		line-height: 84upx;
		border-radius: 44upx;
		font-size: 32upx;
		background: linear-gradient(left, #FF978D, #FFBB69);
	}

	.login-btn {
		padding: 10upx 20upx;
		margin-top: 350upx;
	}

	.login-function {
		overflow: auto;
		padding: 20upx 20upx 30upx 20upx;
	}

	.login-forget {
		float: left;
		font-size: 26upx;
		color: #999;
	}

	.login-register {
		color: #666;
		float: right;
		font-size: 26upx;

	}

	.login-input input {
		background: #F2F5F6;
		font-size: 28upx;
		padding: 10upx 25upx;
		height: 62upx;
		line-height: 62upx;
		border-radius: 8upx;
	}

	.login-margin-b {
		margin-bottom: 25upx;
	}

	.login-input {
		padding: 10upx 20upx;
	}

	.login-head {
		font-size: 34upx;
		text-align: center;
		padding: 25upx 10upx 55upx 10upx;
	}

	.login-card {
		background: #fff;
		border-radius: 12upx;
		padding: 10upx 25upx;
		box-shadow: 0 6upx 18upx rgba(0, 0, 0, 0.12);
		position: relative;
		margin-top: 120upx;
	}

	.login-bg {
		height: 260upx;
		padding: 25upx;
		background: linear-gradient(#2979ff, #ecf5ff);
	}
</style>
